package com.ss.android.article.base.feature.feed.vh;

import android.content.Context;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.c.FeedItemBehavior;
import com.ss.android.article.base.feature.feed.activity.InfoLayout;
import com.ss.android.article.base.feature.model.DownloadAppAd;
import com.ss.android.article.browser.R;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.download.DownloadAdapterProxy;
import com.ss.android.common.download.DownloadInfoChangeListener;
import com.ss.android.common.download.DownloadShortInfo;
import com.ss.android.common.util.NetworkStatusMonitor;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.a.TimeFormatter;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONObject;

import java.util.concurrent.atomic.AtomicBoolean;

public final class AppAdViewHolder extends af {
    final static class DownloadNotifier implements DownloadInfoChangeListener {
        public final AppAdViewHolder mAppAdViewHolder;
        long mId;

        DownloadNotifier(AppAdViewHolder appAdViewHolder) {
            this.mAppAdViewHolder = appAdViewHolder;
        }

        public final void setDownloadId(long id) {
            this.mId = id;
        }

        public final void onDownloadProgressChanged(final DownloadShortInfo downloadInfo, final int arg11, final long arg12, final long arg14, long arg16) {
            this.mAppAdViewHolder.duplicatePressedRelativeLayout.post(new Runnable() {

                public final void run() {
                    long v6_2;
                    ViewGroup v6_1;
                    int v5;
                    ProgressBar v6;
                    String v0_1;
                    String v1;
                    String v2;
                    int v9 = 2;
                    int v3 = 0;
                    int v4 = 8;
                    if (downloadInfo != null && downloadInfo.id == DownloadNotifier.this.mId) {
                        Logger.d("AppAdViewHolder", "mId = " + DownloadNotifier.this.mId
                                + " info.id = " + downloadInfo.id
                                + " fileName = " + downloadInfo.fileName);
                        try {
                            DownloadNotifier.this.mAppAdViewHolder.mDownloadInfo = downloadInfo;
                            v2 = "";
                            v1 = "";
                            v0_1 = "";
                            v6 = DownloadNotifier.this.mAppAdViewHolder.mActionAdProgress;
                            if (DownloadNotifier.this.mAppAdViewHolder.s()) {
                                v5 = v4;
                            } else {
                                v5 = 0;
                            }

                            v6.setVisibility(v5);
                            v6_1 = DownloadNotifier.this.mAppAdViewHolder.mAdDownloadProgressLayout;
                            if (DownloadNotifier.this.mAppAdViewHolder.s()) {
                                v5 = v4;
                            } else {
                                v5 = 0;
                            }
                            v6_1.setVisibility(v5);
                            DownloadNotifier.this.mAppAdViewHolder.mAdDetailInfoTv.setVisibility(View.GONE);
                            if (arg11 == 1) {
                                Logger.d("AppAdViewHolder", "mAppAd.mId = " + DownloadNotifier.this.mAppAdViewHolder.o.id
                                        + ", status == DownloadNotifier.TYPE_ACTIVE");
                                v2 = android.support.design.a.a(arg14) + "/" + android.support.design.a.a(arg12);
                                int v0_2 = ((int) (arg14 * 100 / arg12));
                                v1 = DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kb);
                                if (DownloadNotifier.this.mAppAdViewHolder.s()) {
                                    DownloadNotifier.this.mAppAdViewHolder.mAdNameTv.setText(
                                            DownloadNotifier.this.mAppAdViewHolder.resources.getString(
                                                    com.ss.android.article.browser.R.string.kc) + String.valueOf(v0_2) + "%");
                                }

                                v0_1 = DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kf);
                                UIUtils.setBackgroundResource(DownloadNotifier.this.mAppAdViewHolder.mAdActionBtnLayout, R.color.transparent);
                                DownloadNotifier.this.mAppAdViewHolder.b(com.ss.android.article.browser.R.color.ssxinzi8);
                            } else {
                                if (arg11 == v9) {
                                    Logger.d("AppAdViewHolder", "mAppAd.mId = " + DownloadNotifier.this.mAppAdViewHolder.o.id
                                            + ", status == DownloadNotifier.TYPE_WAITING");
                                    v2 = android.support.design.a.a(arg14) + "/" + android.support.design.a.a(arg12);
                                    v3 = ((int) (arg14 * 100 / arg12));
                                    v1 = DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kf);
                                    v0_1 = DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.ki);
                                    if (DownloadNotifier.this.mAppAdViewHolder.s()) {
                                        DownloadNotifier.this.mAppAdViewHolder.mAdNameTv.setText(DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kg) + String.valueOf(v3) + "%");
                                    }

                                    UIUtils.setBackgroundResource(DownloadNotifier.this.mAppAdViewHolder.mAdActionBtnLayout, R.color.transparent);
                                    DownloadNotifier.this.mAppAdViewHolder.b(com.ss.android.article.browser.R.color.ssxinzi8);
                                    com.ss.android.article.base.feature.b.a v3_1 = android.support.design.a.c(DownloadNotifier.this.mAppAdViewHolder.o.id);
                                    if (v3_1 == null) {
                                    } else {
                                        v3_1.c += System.currentTimeMillis() - v3_1.b;
                                        v3_1.b = System.currentTimeMillis();
                                        android.support.design.a.a(v3_1, false);
                                    }
                                } else if (arg11 != 3) {
                                } else {
                                    Logger.d("AppAdViewHolder", "mAppAd.mId = " + DownloadNotifier.this.mAppAdViewHolder.o.id + ", status == DownloadNotifier.TYPE_COMPLETE");
                                    TextView v5_1 = DownloadNotifier.this.mAppAdViewHolder.mAdDetailInfoTv;
                                    if (DownloadNotifier.this.mAppAdViewHolder.s()) {
                                        v3 = v4;
                                    }

                                    v5_1.setVisibility(v3);
                                    DownloadNotifier.this.mAppAdViewHolder.mAdDownloadProgressLayout.setVisibility(View.GONE);
                                    DownloadNotifier.this.mAppAdViewHolder.mActionAdProgress.setVisibility(View.GONE);
                                    if (DownloadNotifier.this.mAppAdViewHolder.mDownloadInfo.b == 16) {
                                        com.ss.android.article.base.feature.b.a v0_3 = android.support.design.a.c(DownloadNotifier.this.mAppAdViewHolder.o.id);
                                        Logger.d("AppAdViewHolder", "mAppAd.mId = " + DownloadNotifier.this.mAppAdViewHolder.o.id + ", download fail");
                                        if (v0_3 != null) {
                                            v6_2 = System.currentTimeMillis() - v0_3.b + v0_3.c;
                                            v1 = DownloadNotifier.this.mAppAdViewHolder.a(DownloadNotifier.this.mAppAdViewHolder.mDownloadInfo.id);
                                            JSONObject v8 = new JSONObject();
                                            v8.put("fail_status", v1);
                                            v8.put("duration", v6_2);
                                            v8.put("log_extra", DownloadNotifier.this.mAppAdViewHolder.o.logExtra);
                                            Logger.d("AppAdViewHolder", "mAppAd.mId = " + DownloadNotifier.this.mAppAdViewHolder.o.id + ", download fail, duration = " + v6_2 + ", failedReason = " + v1);
                                            MobAdClickCombiner.onAdEvent(DownloadNotifier.this.mAppAdViewHolder.context, "feed_download_ad", "download_fail", DownloadNotifier.this.mAppAdViewHolder.o.id, v6_2, v8, 2);
                                            android.support.design.a.a(v0_3, true);
                                        }

                                        v2 = android.support.design.a.a(arg12);
                                        v1 = DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kd);
                                        v0_1 = DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kh);
                                        if (DownloadNotifier.this.mAppAdViewHolder.s()) {
                                            UIUtils.setBackgroundResource(DownloadNotifier.this.mAppAdViewHolder.mAdActionBtnLayout, R.color.transparent);
                                        } else {
                                            UIUtils.setBackgroundResource(DownloadNotifier.this.mAppAdViewHolder.mAdActionBtnLayout, R.drawable.ag);
                                        }
                                        DownloadNotifier.this.mAppAdViewHolder.b(com.ss.android.article.browser.R.color.d1);
                                        DownloadNotifier.this.mAppAdViewHolder.q();
                                    } else {
                                        if (DownloadNotifier.this.mAppAdViewHolder.mDownloadInfo.b != v4) {
                                        } else {
                                            if (!ToolUtils.d(DownloadNotifier.this.mAppAdViewHolder.context, DownloadNotifier.this.mAppAdViewHolder.mDownloadInfo.fileName)) {
                                                v0_1 = DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.k9);
                                            } else if (!android.support.design.a.isTextEmpty(DownloadNotifier.this.mAppAdViewHolder.o.btnTxt)) {
                                                v0_1 = DownloadNotifier.this.mAppAdViewHolder.o.btnTxt;
                                            } else {
                                                v0_1 = DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.ke);
                                            }

                                            DownloadNotifier.this.mAppAdViewHolder.b(com.ss.android.article.browser.R.color.cx);
                                            if (DownloadNotifier.this.mAppAdViewHolder.s()) {
                                                UIUtils.setBackgroundResource(DownloadNotifier.this.mAppAdViewHolder.mAdActionBtnLayout, R.color.transparent);
                                            } else {
                                                UIUtils.setBackgroundResource(DownloadNotifier.this.mAppAdViewHolder.mAdActionBtnLayout, R.drawable.ae);
                                            }

                                            String v11 = android.support.design.a.a(arg12);
                                            String v10 = DownloadNotifier.this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.k_);
                                            com.ss.android.article.base.feature.b.a v12 = android.support.design.a.c(DownloadNotifier.this.mAppAdViewHolder.o.id);
                                            if (v12 != null) {
                                                v6_2 = System.currentTimeMillis() - v12.b + v12.c;
                                                Logger.d("AppAdViewHolder", "mAppAd.mId = " + DownloadNotifier.this.mAppAdViewHolder.o.id + ", download success, duration = " + v6_2);
                                                MobAdClickCombiner.onAdEvent(DownloadNotifier.this.mAppAdViewHolder.context, "feed_download_ad", "download_success", DownloadNotifier.this.mAppAdViewHolder.o.id, v6_2, DownloadNotifier.this.mAppAdViewHolder.o.logExtra, 2);
                                                android.support.design.a.a(v12, true);
                                            }
                                            v1 = v10;
                                            v2 = v11;
                                            DownloadNotifier.this.mAppAdViewHolder.q();
                                        }
                                    }
                                    DownloadNotifier.this.mAppAdViewHolder.mActionAdProgress.setVisibility(View.GONE);
                                }
                            }

                            if (arg12 > 0) {
                                DownloadNotifier.this.mAppAdViewHolder.mActionAdProgress.setProgress(((int) (arg14 * 100 / arg12)));
                            } else {
                                DownloadNotifier.this.mAppAdViewHolder.mActionAdProgress.setProgress(0);
                            }

                            if (DownloadNotifier.this.mAppAdViewHolder.s()) {
                                DownloadNotifier.this.mAppAdViewHolder.mActionAdTv.setText(((CharSequence) v0_1));
                                UIUtils.setVisibility(DownloadNotifier.this.mAppAdViewHolder.mAdDownloadProgressLayout, 8);
                                UIUtils.setVisibility(DownloadNotifier.this.mAppAdViewHolder.mAdDetailInfoTv, 8);
                            }

                            if (DownloadNotifier.this.mAppAdViewHolder.mAdDownloadProgressLayout.getVisibility() == View.VISIBLE) {
                                DownloadNotifier.this.mAppAdViewHolder.mAdDownloadSize.setText(((CharSequence) v2));
                                DownloadNotifier.this.mAppAdViewHolder.mAdDownloadStatus.setText(((CharSequence) v1));
                                DownloadNotifier.this.mAppAdViewHolder.mActionAdTv.setText(((CharSequence) v0_1));
                            }

                            if (DownloadNotifier.this.mAppAdViewHolder.mAdDetailInfoTv.getVisibility() != View.VISIBLE) {
                                return;
                            }

                            DownloadNotifier.this.mAppAdViewHolder.mAdDetailInfoTv.setText(v2 + "  " + v1);
                            DownloadNotifier.this.mAppAdViewHolder.mActionAdTv.setText(((CharSequence) v0_1));
                        } catch (Exception exception) {
                            exception.printStackTrace();
                        }
                    }
                }
            });
        }
    }

    public static final class QueryDownloadInfoTask extends AsyncTask {
        private final AppAdViewHolder mAppAdViewHolder;

        public QueryDownloadInfoTask(AppAdViewHolder viewHolder) {
            this.mAppAdViewHolder = viewHolder;

        }

        protected final Object doInBackground(Object[] arg7) {
            DownloadShortInfo result;
            if (arg7 != null) {
                if (arg7.length > 0 && (TextUtils.isEmpty((String) arg7[0]))) {
                    return null;
                }

                if (this.mAppAdViewHolder.context == null) {
                    return null;
                }

                Object url = arg7[0];
                result = DownloadAdapterProxy.inst().queryDownloadInfo(this.mAppAdViewHolder.context, ((String) url));
                if (result != null) {
                    Logger.d("AppAdViewHolder queryDownloadInfo", "result.id = " + result.id + " url = " + url + " fileName = " + result.fileName);
                } else {
                    return null;
                }
            } else {
                result = null;
            }

            return result;
        }

        protected final void onPostExecute(Object result) {
            String v1_3;
            TextView v0_4;
            ProgressBar v1_2;
            int v0_2;
            ViewGroup v1;
            long v10 = 100;
            String v7 = null;
            int v8 = View.GONE;
            super.onPostExecute(result);
            if (!this.isCancelled()) {
                boolean v0 = AppUtil.a(this.mAppAdViewHolder.context, this.mAppAdViewHolder.o.version, this.mAppAdViewHolder.o.pkg);
                try {
                    if ((AppData.getInstance().allowInsideDownloadManager()) && result != null
                            && ((DownloadShortInfo) result).id > -1
                            && !DownloadAdapterProxy.inst().isDownloadSuccessAndFileNotExist(this.mAppAdViewHolder.context, ((DownloadShortInfo) result)) && !v0) {
                        if (result != null) {
                            Logger.d("AppAdViewHolder QueryDownloadInfoTask", "result.id = " + ((DownloadShortInfo) result).id
                                    + " fileName = " + ((DownloadShortInfo) result).fileName);
                            DownloadAdapterProxy.inst().registerDownloadListener(this.mAppAdViewHolder.context,
                                    Long.valueOf(((DownloadShortInfo) result).id), this.mAppAdViewHolder.q, String.valueOf(this.mAppAdViewHolder.o.id), 1, this.mAppAdViewHolder.o.logExtra);
                        }

                        this.mAppAdViewHolder.mDownloadInfo = ((DownloadShortInfo) result);
                        this.mAppAdViewHolder.mAdDetailInfoTv.setVisibility(View.GONE);
                        v1 = this.mAppAdViewHolder.mAdDownloadProgressLayout;
                        v0_2 = this.mAppAdViewHolder.s() ? v8 : 0;
                        v1.setVisibility(v0_2);
                        v1_2 = this.mAppAdViewHolder.mActionAdProgress;
                        v0_2 = this.mAppAdViewHolder.s() ? v8 : 0;
                        v1_2.setVisibility(v0_2);
                        String v0_5;
                        switch (((DownloadShortInfo) result).b) {
                            case 1:
                            case 2: {
                                String v9 = android.support.design.a.a(((DownloadShortInfo) result).d) + "/" + android.support.design.a.a(((DownloadShortInfo) result).c);
                                v0_2 = ((int) (((DownloadShortInfo) result).d * v10 / ((DownloadShortInfo) result).c));
                                String v8_1 = this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kb);
                                v7 = this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kf);
                                UIUtils.setBackgroundResource(this.mAppAdViewHolder.mAdActionBtnLayout, com.ss.android.article.browser.R.color.transparent);
                                this.mAppAdViewHolder.b(com.ss.android.article.browser.R.color.ssxinzi8);
                                if (this.mAppAdViewHolder.s()) {
                                    this.mAppAdViewHolder.mAdNameTv.setText(this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kc) + String.valueOf(v0_2) + "%");
                                }

                                DownloadAdapterProxy.inst().registerDownloadListener(this.mAppAdViewHolder.context, Long.valueOf(((DownloadShortInfo) result).id), this.mAppAdViewHolder.q, String.valueOf(this.mAppAdViewHolder.o.id), 1, this.mAppAdViewHolder.o.logExtra);
                                v0_5 = v7;
                                v1_3 = v9;
                                v7 = v8_1;
                                break;
                            }
                            case 4: {
                                v1_3 = android.support.design.a.a(((DownloadShortInfo) result).d) + "/" + android.support.design.a.a(((DownloadShortInfo) result).c);
                                int v2_1 = ((int) (((DownloadShortInfo) result).d * v10 / ((DownloadShortInfo) result).c));
                                v7 = this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kf);
                                v0_5 = this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.ki);
                                UIUtils.setBackgroundResource(this.mAppAdViewHolder.mAdActionBtnLayout, com.ss.android.article.browser.R.color.transparent);
                                this.mAppAdViewHolder.b(com.ss.android.article.browser.R.color.ssxinzi8);
                                if (!this.mAppAdViewHolder.s()) {
                                } else {
                                    this.mAppAdViewHolder.mAdNameTv.setText(this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kg) + String.valueOf(v2_1) + "%");
                                }
                                break;
                            }
                            case 8: {
                                if (ToolUtils.d(this.mAppAdViewHolder.context, ((DownloadShortInfo) result).fileName)) {
                                    v0_5 = this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.ke);
                                } else {
                                    v0_5 = this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.k9);
                                }
                                this.mAppAdViewHolder.b(com.ss.android.article.browser.R.color.cx);
                                if (this.mAppAdViewHolder.s()) {
                                    UIUtils.setBackgroundResource(this.mAppAdViewHolder.mAdActionBtnLayout, com.ss.android.article.browser.R.color.transparent);
                                } else {
                                    UIUtils.setBackgroundResource(this.mAppAdViewHolder.mAdActionBtnLayout, com.ss.android.article.browser.R.drawable.ae);
                                }
                                TextView v2_2 = this.mAppAdViewHolder.mAdDetailInfoTv;
                                int v1_4 = this.mAppAdViewHolder.s() ? v8 : View.VISIBLE;
                                v2_2.setVisibility(v1_4);
                                this.mAppAdViewHolder.mAdDownloadProgressLayout.setVisibility(View.GONE);
                                this.mAppAdViewHolder.mActionAdProgress.setVisibility(View.GONE);
                                v1_3 = android.support.design.a.a(((DownloadShortInfo) result).d);
                                v7 = this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.k_);
                                if (this.mAppAdViewHolder.o != null && this.mAppAdViewHolder.mAdNameTv != null && !android.support.design.a.isTextEmpty(this.mAppAdViewHolder.o.appName)) {
                                    this.mAppAdViewHolder.mAdNameTv.setText(this.mAppAdViewHolder.o.appName);
                                }
                                break;
                            }
                            case 16: {
                                v0_4 = this.mAppAdViewHolder.mAdDetailInfoTv;
                                if (!this.mAppAdViewHolder.s()) {
                                    v8 = 0;
                                }

                                label_159:
                                v0_4.setVisibility(v8);
                                this.mAppAdViewHolder.mAdDownloadProgressLayout.setVisibility(View.GONE);
                                this.mAppAdViewHolder.mActionAdProgress.setVisibility(View.GONE);
                                v1_3 = android.support.design.a.a(((DownloadShortInfo) result).c);
                                v7 = this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kd);
                                v0_5 = this.mAppAdViewHolder.resources.getString(com.ss.android.article.browser.R.string.kh);
                                if (this.mAppAdViewHolder.s()) {
                                    UIUtils.setBackgroundResource(this.mAppAdViewHolder.mAdActionBtnLayout, com.ss.android.article.browser.R.color.transparent);
                                } else {
                                    UIUtils.setBackgroundResource(this.mAppAdViewHolder.mAdActionBtnLayout, com.ss.android.article.browser.R.drawable.ag);
                                }
                                if (this.mAppAdViewHolder.s()) {
                                    this.mAppAdViewHolder.q();
                                    if (this.mAppAdViewHolder.o != null && this.mAppAdViewHolder.mAdNameTv != null && !android.support.design.a.isTextEmpty(this.mAppAdViewHolder.o.appName)) {
                                        this.mAppAdViewHolder.mAdNameTv.setText(this.mAppAdViewHolder.o.appName);
                                    }
                                }

                                this.mAppAdViewHolder.b(com.ss.android.article.browser.R.color.d1);
                                break;
                            }
                            default: {
                                v0_5 = ((String) v7);
                                v1_3 = v7;
                                break;
                            }
                        }
                        if (((DownloadShortInfo) result).c > 0) {
                            this.mAppAdViewHolder.mActionAdProgress.setProgress(((int) (((DownloadShortInfo) result).d * v10 / ((DownloadShortInfo) result).c)));
                        } else {
                            this.mAppAdViewHolder.mActionAdProgress.setProgress(0);
                        }
                        if (this.mAppAdViewHolder.s()) {
                            this.mAppAdViewHolder.mActionAdTv.setText(((CharSequence) v0_5));
                            UIUtils.setVisibility(this.mAppAdViewHolder.mAdDownloadProgressLayout, 8);
                            UIUtils.setVisibility(this.mAppAdViewHolder.mAdDetailInfoTv, 8);
                        }

                        if (this.mAppAdViewHolder.mAdDownloadProgressLayout.getVisibility() == View.VISIBLE) {
                            if (!android.support.design.a.isTextEmpty(v1_3)) {
                                this.mAppAdViewHolder.mAdDownloadSize.setText(v1_3);
                            }
                            if (!android.support.design.a.isTextEmpty(v7)) {
                                this.mAppAdViewHolder.mAdDownloadStatus.setText(v7);
                            }
                            if (android.support.design.a.isTextEmpty(v0_5)) {
                            } else {
                                this.mAppAdViewHolder.mActionAdTv.setText(v0_5);
                            }
                        }
                        if (this.mAppAdViewHolder.mAdDetailInfoTv.getVisibility() != View.VISIBLE) {
                            return;
                        }

                        if (!android.support.design.a.isTextEmpty(v1_3) && !android.support.design.a.isTextEmpty(v7)) {
                            this.mAppAdViewHolder.mAdDetailInfoTv.setText(v1_3 + "  " + v7);
                        }

                        if (android.support.design.a.isTextEmpty(v0_5)) {
                            return;
                        }
                        this.mAppAdViewHolder.mActionAdTv.setText(v0_5);
                        return;
                    }

                    if (this.mAppAdViewHolder.mDownloadInfo != null) {
                        DownloadAdapterProxy.inst()
                                .unregisterDownloadListener(
                                        this.mAppAdViewHolder.context,
                                        Long.valueOf(this.mAppAdViewHolder.mDownloadInfo.id),
                                        this.mAppAdViewHolder.q);
                    }

                    this.mAppAdViewHolder.mDownloadInfo = null;
                    TextView v1_1 = this.mAppAdViewHolder.mActionAdTv;
                    Resources v2 = this.mAppAdViewHolder.resources;
                    if (v0) {
                        v0_2 = com.ss.android.article.browser.R.string.kj;
                    } else {
                        v0_2 = com.ss.android.article.browser.R.string.ka;
                    }

                    v1_1.setText(v2.getString(v0_2));
                    if (this.mAppAdViewHolder.s()) {
                        UIUtils.setBackgroundResource(this.mAppAdViewHolder.mAdActionBtnLayout, com.ss.android.article.browser.R.color.transparent);
                    } else {
                        this.mAppAdViewHolder.mAdActionBtnLayout.setBackgroundResource(com.ss.android.article.browser.R.drawable.ad_action_btn_begin_bg);
                    }

                    this.mAppAdViewHolder.b(com.ss.android.article.browser.R.color.ad_action_btn_begin_text_color);
                    this.mAppAdViewHolder.mAdDownloadProgressLayout.setVisibility(View.GONE);
                    this.mAppAdViewHolder.mActionAdProgress.setVisibility(View.GONE);
                    this.mAppAdViewHolder.mAdDetailInfoTv.setVisibility(View.GONE);
                    this.mAppAdViewHolder.p();
                    return;
                } catch (Exception v0_1) {
                }
            }
        }
    }

    public DownloadAppAd o;
    public DownloadShortInfo mDownloadInfo;
    public final DownloadNotifier q;
    private View.OnClickListener u;
    private QueryDownloadInfoTask mQueryDownloadInfoTask;
    private boolean w;
    private View.OnClickListener x;

    public AppAdViewHolder(Context context, NetworkStatusMonitor networkStatusMonitor, FeedItemBehavior feedItemBehavior,
                           ArticleActionHelper articleActionHelper, int arg6, TimeFormatter timeFormatter,
                           int arg8, int arg9, int arg10, int arg11, int arg12, AtomicBoolean arg13) {
        super(context, networkStatusMonitor, feedItemBehavior, articleActionHelper, arg6, timeFormatter, arg8, arg9, arg10, arg11, arg12, arg13);
        this.u = new View.OnClickListener() {

            public final void onClick(View arg3) {
                if (!android.support.design.a.isTextEmpty(mCellRef.sourceOpenUrl)) {
                    AppUtil.b(AppAdViewHolder.this.context, mCellRef.sourceOpenUrl);
                }
            }
        };
        this.q = new DownloadNotifier(this);
        this.x = new View.OnClickListener() {

            public final void onClick(View arg3) {
                AppAdViewHolder.this.a(2);
            }
        };
    }

    public final String a(long arg4) {
        return DownloadAdapterProxy.inst().getFailedReson(this.context, arg4);
    }

    final void a(int arg9) {
        DownloadShortInfo v3 = null;
        if (this.o != null) {
            this.o.J = System.currentTimeMillis();
            if (AppData.getInstance().allowInsideDownloadManager()) {
                this.o.a(this.context, arg9, this.mDownloadInfo, this.q, 1);
            } else {
                this.o.a(this.context, arg9, v3, ((DownloadInfoChangeListener) null), 1);
            }
        }
    }

    public final void a(View arg2) {
        this.a(1);
    }

    protected final void a_(InfoLayout.Info arg4) {
        if (this.o != null && (this.mCellRef.n())) {
            String v0 = this.w ? this.o.appName : this.o.appAdSource;
            if (android.support.design.a.isTextEmpty(v0)) {
                return;
            }

            if (android.support.design.a.isTextEmpty(v0.trim())) {
                return;
            }

            if ((this.s()) || (this.w)) {
                if (this.mCellRef.o()) {
                    arg4.a |= 128;
                }

                arg4.a |= 256;
            }

            if (b(this.o.h, this.mCellRef.subTitle)) {
                arg4.a |= 256;
            }

            arg4.a |= 1;
            arg4.d = v0;
        }
    }

    protected final void a_(boolean isDownload) {
        int v2 = View.GONE;
        super.a_(isDownload);
        if (this.mAppAdInfoLayout != null) {
            this.mAdNameTv.setTextColor(ContextCompat.getColor(this.context, com.ss.android.article.browser.R.color.ssxinzi3));
            if (this.s()) {
                this.mAdNameTv.setTextSize(17f);
                this.mAdDetailInfoTv.setVisibility(v2);
                if (this.mAdDownloadProgressLayout != null) {
                    this.mAdDownloadProgressLayout.setVisibility(v2);
                }
            } else {
                this.mAdNameTv.setTextSize(15f);
                this.mAdDetailInfoTv.setTextSize(12f);
                this.mAdDetailInfoTv.setVisibility(View.VISIBLE);
            }

            this.mAdDetailInfoTv.setTextColor(ContextCompat.getColor(this.context, com.ss.android.article.browser.R.color.cg));
            if (!isDownload) {
                return;
            }
            this.initAdDownloadProgress();
        }
    }

    final void b(int arg4) {
        if (this.s()) {
            this.mActionAdTv.setTextColor(this.resources.getColorStateList(com.ss.android.article.browser.R.color.xy));
            this.mActionAdTv.setTextSize(17f);
        } else {
            this.mActionAdTv.setTextColor(this.resources.getColor(arg4));
            this.mActionAdTv.setTextSize(12f);
        }
    }

    protected final void g() {
        InfoLayout v0_1;
        LinearLayout.LayoutParams v1;
        ViewGroup.LayoutParams v0;
        float v6 = 6f;
        int v5 = com.ss.android.article.browser.R.dimen.list_item_horizontal_outside_padding;
        int v3 = com.ss.android.article.browser.R.dimen.feed_item_horizontal_margin;
        int v8 = View.GONE;
        if (this.mCellRef != null) {
            this.o = this.mCellRef.downloadAppAd;
            if (this.o != null) {
                super.g();
                this.w = this.mCellRef.j();
                switch (this.o.h) {
                    case 1: {
                        this.initRightImageAdLayout();
                        if (this.mRightImageAdInfoLayout == null) {
                        } else if (this.w) {
                            v0 = this.mRightImageAdInfoLayout.getLayoutParams();
                            ((RelativeLayout.LayoutParams) v0).addRule(10);
                            this.mRightImageAdInfoLayout.setLayoutParams(v0);
                        } else {
                            v0 = this.mRightImageAdInfoLayout.getLayoutParams();
                            ((RelativeLayout.LayoutParams) v0).addRule(15);
                            this.mRightImageAdInfoLayout.setLayoutParams(v0);
                        }

                        break;
                    }
                    case 2: {
                        this.initLargeImageAdInfoLayout();
                        break;
                    }
                    case 3: {
                        this.initMultiImageAdLayout();
                        break;
                    }
                    case 4: {
                        this.initRightImageAdImageLayout();
                        if (this.mRightImageAdInfoLayout == null) {
                        } else if (this.w) {
                            v0 = this.mRightImageAdInfoLayout.getLayoutParams();
                            ((RelativeLayout.LayoutParams) v0).addRule(10);
                            this.mRightImageAdInfoLayout.setLayoutParams(v0);
                        } else {
                            v0 = this.mRightImageAdInfoLayout.getLayoutParams();
                            ((RelativeLayout.LayoutParams) v0).addRule(15);
                            this.mRightImageAdInfoLayout.setLayoutParams(v0);
                        }

                        break;
                    }
                }

                this.t();
                if (this.w) {
                    UIUtils.setVisibility(this.mRightInfoLayoutGroup, v8);
                    UIUtils.setVisibility(this.mImage3InfoLayout, v8);
                    UIUtils.setVisibility(this.mNewInfoLayout, 0);
                } else {
                    UIUtils.setVisibility(this.mNewInfoLayout, v8);
                }

                this.e(this.o.h);
                this.g(this.o.h);
                this.c(this.o.h);
                if (this.mActionAdDivider != null) {
                    if (this.s()) {
                        this.mActionAdDivider.setVisibility(View.VISIBLE);
                    } else {
                        this.mActionAdDivider.setVisibility(v8);
                    }
                }

                this.a(this.o.appAdDescription, this.o.h);
                this.a(this.o.imageInfo);
                if (this.w) {
                    v1 = new LinearLayout.LayoutParams(-1, -2);
                    switch (this.m()) {
                        case 1:
                        case 2: {
                            v0_1 = this.mImage3InfoLayout;
                            if (!this.mAppData.getAppSettings().isFeedCellSpacingChange()) {
                                v1.setMargins(this.context.getResources().getDimensionPixelOffset(v3), 0, this.context.getResources().getDimensionPixelOffset(v5), this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.feed_info_layout_margin_bottom));
                            } else if (this.mAppData.getAppSettings().isMaxCellSpacingChange()) {
                                v1.setMargins(this.context.getResources().getDimensionPixelOffset(v3), 0, this.context.getResources().getDimensionPixelOffset(v5), ((int) UIUtils.dp2px(this.context, v6)));
                            } else {
                                v1.setMargins(this.context.getResources().getDimensionPixelOffset(v3), 0, this.context.getResources().getDimensionPixelOffset(v5), ((int) UIUtils.dp2px(this.context, 7f)));
                            }

                            v0_1.setLayoutParams(((ViewGroup.LayoutParams) v1));
                            break;
                        }
                        default: {
                            v0_1 = null;
                            break;
                        }
                    }

                    if (v0_1 != null) {
                        v0_1.setVisibility(View.VISIBLE);
                    }

                    if (this.mNewInfoLayoutStub == null) {
                        this.mNewInfoLayoutStub = this.duplicatePressedRelativeLayout.findViewById(com.ss.android.article.browser.R.id.new_info_layout_stub);
                    }

                    if (this.mNewInfoLayout == null) {
                        this.mNewInfoLayoutStub.inflate();
                        this.mNewInfoLayout = this.duplicatePressedRelativeLayout.findViewById(com.ss.android.article.browser.R.id.new_info_layout);
                    }

                    this.mNewInfoLayout.setVisibility(View.VISIBLE);
                    InfoLayout.Info v0_2 = InfoLayout.Info.acquireInfo();
                    this.a(v0_2);
                    this.a_(v0_2);
                    this.h(v0_2);
                    this.g(v0_2);
                    this.mNewInfoLayout.setDislikeOnClickListener(this.popIconClickListener);
                    this.mNewInfoLayout.setSourceOnClickListener(this.u);
                    this.mNewInfoLayout.a(v0_2);
                } else {
                    v1 = new LinearLayout.LayoutParams(-1, -2);
                    switch (this.m()) {
                        case 1:
                        case 2: {
                            v0_1 = this.mImage3InfoLayout;
                            if (!this.mAppData.getAppSettings().isFeedCellSpacingChange()) {
                                v1.setMargins(this.context.getResources().getDimensionPixelOffset(v3),
                                        this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.e_),
                                        this.context.getResources().getDimensionPixelOffset(v5),
                                        this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.feed_info_layout_margin_bottom));
                            } else if (this.mAppData.getAppSettings().isMaxCellSpacingChange()) {
                                v1.setMargins(this.context.getResources().getDimensionPixelOffset(v3),
                                        ((int) UIUtils.dp2px(this.context, 4f)),
                                        this.context.getResources().getDimensionPixelOffset(v5),
                                        ((int) UIUtils.dp2px(this.context, v6)));
                            } else {
                                v1.setMargins(this.context.getResources().getDimensionPixelOffset(v3),
                                        ((int) UIUtils.dp2px(this.context, 5f)),
                                        this.context.getResources().getDimensionPixelOffset(v5),
                                        ((int) UIUtils.dp2px(this.context, 7f)));
                            }

                            v0_1.setLayoutParams(((ViewGroup.LayoutParams) v1));
                            break;
                        }
                        case 3: {
                            v0_1 = this.mImage3InfoLayout;
                            v1.setMargins(this.context.getResources().getDimensionPixelOffset(v3), this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.e_), this.context.getResources().getDimensionPixelOffset(v5), 2);
                            v0_1.setLayoutParams(((ViewGroup.LayoutParams) v1));
                            break;
                        }
                        case 4: {
                            v0_1 = this.mRightInfoLayoutGroup;
                            if (this.mAppData.getAppSettings().isSingleImageGravityChange()) {
                                v1.setMargins(((int) UIUtils.dp2px(this.context, 10f)), this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.hb), 0, 0);
                            } else {
                                v1.setMargins(0, this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.hb), this.context.getResources().getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.ha), 0);
                            }

                            v0_1.setLayoutParams(((ViewGroup.LayoutParams) v1));
                            break;
                        }
                        default: {
                            v0_1 = this.mImage3InfoLayout;
                            break;
                        }
                    }

                    if (v0_1 == null) {
                    } else {
                        v0_1.setVisibility(View.VISIBLE);
                        InfoLayout.Info v1_1 = InfoLayout.Info.acquireInfo();
                        this.b(v1_1);
                        v0_1.setDislikeOnClickListener(this.popIconClickListener);
                        v0_1.a(v1_1);
                    }
                }

                this.l();
                this.q();
                UIUtils.setVisibility(this.mActionAdIcon, v8);
                this.a(this.mAppAdInfoLayout, this.o.h);
                UIUtils.setVisibility(this.mLbsAdInfoLayout, v8);
                UIUtils.setVisibility(this.mActionAdInfoLayout, v8);
                UIUtils.setVisibility(this.mAppAdInfoLayout, 0);
                UIUtils.setVisibility(this.mAdNameTv, 0);
                UIUtils.setVisibility(this.mAdActionBtnLayout, 0);
                if (AppData.getInstance().allowInsideDownloadManager()) {
                    if (this.mDownloadInfo != null) {
                        DownloadAdapterProxy.inst().unregisterDownloadListener(this.context, Long.valueOf(this.mDownloadInfo.id), this.q);
                    } else {
                        this.p();
                    }

                    if (this.mQueryDownloadInfoTask != null && this.mQueryDownloadInfoTask.getStatus() != AsyncTask.Status.FINISHED) {
                        this.mQueryDownloadInfoTask.cancel(true);
                    }

                    this.mQueryDownloadInfoTask = new QueryDownloadInfoTask(this);
                    com.bytedance.common.utility.b.a.a(this.mQueryDownloadInfoTask, new String[]{this.o.downloadUrl});
                } else {
                    this.p();
                    UIUtils.setVisibility(this.mAdDownloadProgressLayout, v8);
                    UIUtils.setVisibility(this.mActionAdProgress, v8);
                    if (this.s()) {
                        UIUtils.setBackgroundResource(this.mAdActionBtnLayout, com.ss.android.article.browser.R.color.transparent);
                    } else {
                        UIUtils.setBackgroundResource(this.mAdActionBtnLayout, com.ss.android.article.browser.R.drawable.am);
                    }
                }

                if (!this.s()) {
                    return;
                }

                UIUtils.setVisibility(this.mAdDownloadProgressLayout, v8);
            }
        }
    }

    public final void adaptAdActionBtnLayoutNightMode() {
        int v4 = com.ss.android.article.browser.R.color.ssxinzi8;
        int v3 = View.INVISIBLE;
        int v2 = com.ss.android.article.browser.R.color.transparent;
        if (this.mAdActionBtnLayout != null) {
            if (this.mDownloadInfo != null) {
                if (this.s()) {
                    this.mActionAdProgress.setVisibility(View.GONE);
                } else {
                    this.mActionAdProgress.setVisibility(View.VISIBLE);
                }

                switch (this.mDownloadInfo.b) {
                    case 1:
                    case 2: {
                        label_17:
                        UIUtils.setBackgroundResource(this.mAdActionBtnLayout, v2);
                        this.b(v4);
                        return;
                    }
                    case 8: {
                        label_29:
                        if (this.s()) {
                            UIUtils.setBackgroundResource(this.mAdActionBtnLayout, v2);
                        } else {
                            UIUtils.setBackgroundResource(this.mAdActionBtnLayout, com.ss.android.article.browser.R.drawable.ae);
                        }

                        this.b(com.ss.android.article.browser.R.color.cx);
                        this.mActionAdProgress.setVisibility(v3);
                        return;
                    }
                    case 4:
                    case 16: {
                        label_25:
                        UIUtils.setBackgroundResource(this.mAdActionBtnLayout, v2);
                        this.b(v4);
                        return;
                    }
                }

                return;


            } else {
                if (this.s()) {
                    UIUtils.setBackgroundResource(this.mAdActionBtnLayout, v2);
                } else {
                    UIUtils.setBackgroundResource(this.mAdActionBtnLayout, com.ss.android.article.browser.R.drawable.ad_action_btn_begin_bg);
                }

                this.b(com.ss.android.article.browser.R.color.ad_action_btn_begin_text_color);
                this.mActionAdProgress.setVisibility(v3);
            }
        }
    }

    protected final void j() {
        ViewGroup.LayoutParams v0;
        if (this.mRightImageAdImageLayout != null && this.o != null && this.o.imageInfo != null && (this.o.imageInfo.isValid())) {
            if (this.s()) {
                v0 = this.mRightImageAdImageLayout.getLayoutParams();
                v0.width = com.ss.android.article.base.feature.app.a.b.f;
                v0.height = com.ss.android.article.base.feature.app.a.b.g;
            } else {
                v0 = this.mRightImageAdImageLayout.getLayoutParams();
                v0.width = com.ss.android.article.base.feature.app.a.b.h;
                v0.height = com.ss.android.article.base.feature.app.a.b.h * this.o.imageInfo.mHeight / this.o.imageInfo.mWidth;
            }
        }
    }

    public final void onMovedToScrapHeap() {
        super.onMovedToScrapHeap();
        try {
            if (this.mQueryDownloadInfoTask != null && this.mQueryDownloadInfoTask.getStatus() != AsyncTask.Status.FINISHED) {
                this.mQueryDownloadInfoTask.cancel(true);
            }
            if (this.mDownloadInfo != null) {
                DownloadAdapterProxy.inst().unregisterDownloadListener(this.context, Long.valueOf(this.mDownloadInfo.id), this.q);
            }
        } catch (Exception e) {

        }

        if (this.mImage3InfoLayout != null) {
            ViewGroup.LayoutParams v0_1 = this.mImage3InfoLayout.getLayoutParams();
            if (!this.mAppData.getAppSettings().isFeedCellSpacingChange()) {
                ((ViewGroup.MarginLayoutParams) v0_1).bottomMargin = this.context.getResources().getDimensionPixelSize(com.ss.android.article.browser.R.dimen.feed_info_layout_margin_bottom);
            } else if (this.mAppData.getAppSettings().isMaxCellSpacingChange()) {
                ((ViewGroup.MarginLayoutParams) v0_1).bottomMargin = ((int) UIUtils.dp2px(this.context, 6f));
            } else {
                ((ViewGroup.MarginLayoutParams) v0_1).bottomMargin = ((int) UIUtils.dp2px(this.context, 7f));
            }
        }

        UIUtils.setVisibility(this.mAppAdInfoLayout, 8);
    }

    protected final void l() {
        super.l();
        a(this.mAdActionBtnLayout, this.x);
    }

    protected final void l_() {
        if (this.mLargeImage != null && this.o != null && this.o.imageInfo != null && (this.o.imageInfo.isValid())) {
            b(this.mLargeImage, this.r * this.o.imageInfo.mHeight / this.o.imageInfo.mWidth);
        }
    }

    protected final int m() {
        int v0 = this.o != null ? this.o.h : 0;
        return v0;
    }

    protected final String n() {
        String v0 = this.o == null ? null : this.o.appAdSourceLabel;
        return v0;
    }

    protected final int o() {
        return 10;
    }

    final void p() {
        if (this.o == null || this.mAdDetailInfoTv == null || (this.s())) {
            UIUtils.setVisibility(this.mAdDetailInfoTv, 8);
        } else {
            if ((android.support.design.a.isTextEmpty(this.o.downloadCount)) && (android.support.design.a.isTextEmpty(this.o.appSize))) {
                UIUtils.setVisibility(this.mAdDetailInfoTv, 8);
            } else {
                UIUtils.setVisibility(this.mAdDetailInfoTv, 0);
                String v0 = "";
                if (!android.support.design.a.isTextEmpty(this.o.appSize)) {
                    v0 = this.o.appSize + "  ";
                }

                if (!android.support.design.a.isTextEmpty(this.o.downloadCount)) {
                    v0 = v0 + this.o.downloadCount;
                }

                this.mAdDetailInfoTv.setText(((CharSequence) v0));
            }
        }
    }

    final void q() {
        if (this.mCellRef != null && this.o != null && this.mAdNameTv != null) {
            String v0 = this.mCellRef.subTitle;
            if (!android.support.design.a.isTextEmpty(v0) && !android.support.design.a.isTextEmpty(v0.trim())) {
                this.mAdNameTv.setText(((CharSequence) v0));
                return;
            }

            this.mAdNameTv.setText(this.o.appName);
        }
    }

    protected final void initAdDownloadProgress() {
        if (!this.s()) {
            super.initAdDownloadProgress();
        } else {
            UIUtils.setVisibility(this.mAdDownloadProgressLayout, 8);
        }
    }

    protected final boolean s() {
        boolean v0;
        if (this.o != null) {
            if (this.o.h != 3 && this.o.h != 4) {
                return false;
            }

            v0 = true;
        } else {
            v0 = false;
        }

        return v0;
    }
}

